const app = getApp();
Page({
    data: {
        professRecordEntity:{},
        timeStr:'',
        time:'',
        fontSize:""
    },
    onLoad: function (options) {

        // 监听页面加载的生命周期函数
        if(options.professRecordId == undefined){
            app.showToastFail('参数不合法！')
            return
        }

        this.setData({
            'professRecordEntity.professRecord.id':options.professRecordId
        })

        this.getProfessRecordEntity()
        this.myTime();
    },

    getProfessRecordEntity(){

        swan.request({

            url:app.globalData.URL + `/8100/profess-record/findEntityById/${this.data.professRecordEntity.professRecord.id}`,
            method: 'get',
            success:res=>{

                if(res.data.code != 200){
                    app.showToastFail(res.data.msg)
                    return;
                }

                console.log(res.data.data)

                this.setData({
                    professRecordEntity: res.data.data
                })

            }
        })
    },

    getCountDown(){

        if(this.data.professRecordEntity.professRecord.created == undefined){
            return;
        }

        let created = this.data.professRecordEntity.professRecord.created;
        //console.log("created",created)
        let now = new Date().getTime();
        let createdTime = (new Date(created)).getTime();
        let showtime =  createdTime + 1000*60*60*48 - (now - createdTime - 1000 * 60 * 60 * 8) + 1000 * 60 * 7;

        //console.log("showtime",showtime);

        let nowStr = app.dateFormat("dd HH:MM:SS",new Date())
        let timeStr = app.dateFormat("dd HH:MM:SS",new Date(created))

        let timeStrTime = app.dateFormat("HH:MM:SS",new Date(showtime))

        let nowStrdd = nowStr.split(" ")[0]
        let timeStrdd = timeStr.split(" ")[0]

        //console.log(nowStrdd,"-",timeStrdd)

        let time = timeStrTime;

        if(timeStrdd == nowStrdd){

            time = (Number(timeStrTime.split(":")[0]) + 24)  + ':' +timeStrTime.split(":")[1] + ':' +  timeStrTime.split(":")[2]
        }else if (Number(nowStrdd) > Number(timeStrdd) + 1){

            time = "表白时间超过48小时";
            //  小程序不支持document
            // let times = document.getElementsByClassName("title3");
            // times.style.fontSize = 13 + 'px';
            this.setData({
                fontSize:13+"px"
            })
        }

        //console.log('time',timeStr)

        this.setData({
            timeStr,
            time
        })
    },
    myTime(){
        setInterval(()=>{
           this.getCountDown()
        },999)
    },
    toProfess(e){
        swan.navigateTo({
            url: ''
        });
    },
    onReady: function() {
        // 监听页面初次渲染完成的生命周期函数
    },
    onShow: function() {
        // 监听页面显示的生命周期函数
    },
    onHide: function() {
        // 监听页面隐藏的生命周期函数
    },
    onUnload: function() {
        // 监听页面卸载的生命周期函数
    },
    onPullDownRefresh: function() {
        // 监听用户下拉动作
    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
    },
    onShareAppMessage: function () {
        // 用户点击右上角转发
    }
});